//
//  SCReplayView.m
//  LastOne
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCReplayView.h"
#import <UIImageView+WebCache.h>
#import "FitHeader.h"
#import "NightHeader.h"
@implementation SCReplayView

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)setReplayCountModel:(SCReplayCountModel *)replayCountModel
{
    if (_replayCountModel != replayCountModel) {
        _replayCountModel = replayCountModel;
    }
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:_replayCountModel.timg] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _bLabel.text = _replayCountModel.b;
    _nameLable.text = _replayCountModel.n;
    [_nameLable NightWithType:UIViewColorType2];
    _timeLabel.text = _replayCountModel.t;
}

- (void)createViews
{
    _headImageView = [[UIImageView alloc] init];
    _headImageView.layer.masksToBounds = YES;
    
   // _headImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_headImageView];
    
    _nameLable = [[UILabel alloc] init];
   // _nameLable.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:_nameLable];
    
    _timeLabel = [[UILabel alloc] init];
  //  _timeLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:_timeLabel];
    
    _bLabel = [[UILabel alloc] init];
    _bLabel.font = [UIFont systemFontOfSize:15 * FitWidth];
    _bLabel.numberOfLines = 0;
  //  _bLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_bLabel];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
     NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15 * FitWidth], NSFontAttributeName, nil];
    
     CGRect rect = [_replayCountModel.b boundingRectWithSize:CGSizeMake(375, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    _headImageView.frame = CGRectMake(10 * FitWidth, 10 * FitHeight, 40 * FitWidth, 40 * FitWidth);
    _headImageView.layer.cornerRadius = 20 * FitWidth;
    _nameLable.frame = CGRectMake(_headImageView.frame.origin.x + _headImageView.frame.size.width + 5 * FitWidth, _headImageView.frame.origin.y, 300 * FitWidth, 20 * FitHeight);
    _timeLabel.frame = CGRectMake(_nameLable.frame.origin.x, _nameLable.frame.origin.y + _nameLable.frame.size.height, _nameLable.frame.size.width, _nameLable.frame.size.height);
    _bLabel.frame = CGRectMake(_timeLabel.frame.origin.x, _timeLabel.frame.origin.y + _timeLabel.frame.size.height, _timeLabel.frame.size.width, rect.size.height);
}

@end
